package com.gongpingjialoan.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.bean.Monitor;
import com.gongpingjialoan.utility.StepMonitor;

public class MessageDialog extends Dialog {

	private MessageDialog mySelf = this;
	Context context;
	private Handler messageHanlder;
	private String msg;
	private boolean showUser = false , showChat = false;

	public MessageDialog(Context context, String msg ,boolean showChat , boolean showUser, Handler messageHanlder) {
		super(context,R.style.dialogs);
		this.context = context;
		this.messageHanlder = messageHanlder;
		this.msg = msg;
		this.showUser = showUser;
		this.showChat = showChat;
	}


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.message_dialog);
		if(!showUser){
			findViewById(R.id.sell_car_rl).setVisibility(View.GONE);
		}
		((TextView)findViewById(R.id.message_tip)).setText(msg);
		if(!showChat){
			findViewById(R.id.tips_rl).setVisibility(View.GONE);
		}
		findViewById(R.id.tips_rl).setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if (messageHanlder != null) {
					Message msg = new Message();
					msg.what = 1;
					messageHanlder.sendMessage(msg);
				}
				StepMonitor.getInstance().addMonitor(new Monitor("click", "eval_chatNotReadNotification", System.currentTimeMillis(), 1.0f));
				dismiss();
			}
		});
		findViewById(R.id.sell_car_rl).setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if (messageHanlder != null) {
					Message msg = new Message();
					msg.what = 2;
					messageHanlder.sendMessage(msg);
				}
				StepMonitor.getInstance().addMonitor(new Monitor("click", "eval_personalSellCarNotification", System.currentTimeMillis(), 1.0f));
				dismiss();
			}
		});
        setCanceledOnTouchOutside(true);
    }
}
